package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.service.AdminAuthService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class AdminAuthServiceImpl implements AdminAuthService {

    @Autowired
    SqlSessionFactory sqlSessionFactory;
    @Autowired
    MarketUserMapper userMapper;
    @Autowired
    MarketAdminMapper adminMapper;

    @Override
    @Transactional
    public MarketAdmin login(String username, String password) {
        MarketAdminExample marketAdminExample = new MarketAdminExample();
        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        criteria.andUsernameEqualTo(password);
        MarketAdmin marketAdmin = adminMapper.selectOneByExample(marketAdminExample);
        return marketAdmin;
    }

    @Override
    @Transactional
    public MarketAdmin selectPasswordByName(String username) {
        MarketAdminExample marketAdminExample = new MarketAdminExample();
        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        return adminMapper.selectOneByExample(marketAdminExample);
    }
}
